<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:th="http://www.thymeleaf.org">

<head>
    <th:block th:include="common/common_head :: commonHeader('保存定时任务')"/>
</head>

<body class="gray-bg">

<div class="wrapper wrapper-content animated fadeInRight">
    <form class="form-horizontal" method="post" id="auntLevelForm">
        <div class="row">
            <div class="col-sm-12">
                <div class="ibox float-e-margins">
                    <div class="ibox-content">
                        <input type="hidden" id="id" th:value="${id}">
                        <input type="hidden" id="status">
                        <div class="form-group">
                            <label class="col-sm-3 control-label"><span class="required-sign">*</span>bean名称：</label>
                            <div class="col-sm-5">
                                <input id="beanName" name="beanName" type="text" placeholder="bean名称"
                                       class="form-control">
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">方法名：</label>
                            <div class="col-sm-5">
                                <input id="methodName" name="methodName" type="text" placeholder="方法名"
                                       class="form-control">
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">参数：</label>
                            <div class="col-sm-5">
                                <input id="params" name="params" type="text" placeholder="参数"
                                       class="form-control">
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">cron表达式：</label>
                            <div class="col-sm-5">
                                <input id="cronExpression" name="cronExpression" type="text" placeholder="cron表达式"
                                       class="form-control">
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">备注：</label>
                            <div class="col-sm-5">
                                <textarea class='form-control' id="remark" name='remark' onkeyup='textAreaChange(this,500)' onkeydown='textAreaChange(this,500)' rows='5'></textarea>
                                <div class='text-right'>
                                    <em style='color:red'>0</em>/<span>200</span>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <div class="row">
            <div class="col-sm-12" style="text-align: center">
                <input class="btn btn-primary" type="button" onclick="save()" value="保存" style="margin-right: 20px">
                <button class="btn btn-primary" type="button" onclick="Dialog.closeFrame(window.name)">取 消</button>
            </div>
        </div>
    </form>
</div>

<!--引入公共js-->
<div th:include="common/onload_js :: onloadJS"></div>
<script th:src="@{/static/js/custom/textareaNum.js}"></script>
<script type="text/javascript">
    $(document).ready(function () {
        var id = $("#id").val();
        if (id != "" && id != null) {//编辑
            Page.ajaxPOST(ctxPath+"/sys/schedule/info/"+id, null, function (res) {
                var schedule = res.schedule;
                $("#beanName").val(schedule.beanName);
                $("#methodName").val(schedule.methodName);
                $("#params").val(schedule.params);
                $("#cronExpression").val(schedule.cronExpression);
                $("#remark").val(schedule.remark);
                $("#status").val(schedule.status);
                textAreaChange($("#remark"),200);
            })
        }
    });

    /**
     * 保存
     */
    function save() {
        var id = $("#id").val();
        var beanName = $("#beanName").val();
        if (beanName == null || beanName == "") {
            Dialog.errorMsg("bean名称不能为空");
            return false;
        }
        var methodName = $("#methodName").val();
        if (methodName == null || methodName == "") {
            Dialog.errorMsg("方法名不能为空");
            return false;
        }
        var cronExpression = $("#cronExpression").val();
        if (cronExpression == null || cronExpression == "") {
            Dialog.errorMsg("cron表达式不能为空");
            return false;
        }
        var data = {
            jobId: $("#id").val(),
            beanName: beanName,
            methodName:methodName,
            params:$("#params").val(),
            cronExpression: cronExpression,
            remark:$("#remark").val(),
            status: $("#status").val()
        };
        var url = "/sys/schedule/save";
        if (id != null && id != '') {
            url = "/sys/schedule/update";
        }
        Page.ajaxPOST(ctxPath+url,  JSON.stringify(data), function (res) {
            Dialog.msg("保存成功", function(){
                parent.formSearch();
                Dialog.closeFrame(window.name)
            });
        },{"contentType":"application/json;charset=utf-8"})
    }

</script>
</body>
</html>
